#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

int main()
{
    int n, m;
    std::cin >> n >> m;

    if (n > 100000 || n < 1 || m > 100000 || m < 1)
    {
        std::cout << "NULL" << std::endl;
        return 0;
    }

    std::vector<std::set<int>> team_set;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        std::cin >> a >> b >> c;

        if (a < 1 || a > n || a < 1 || a > n)
        {
            std::cout << "da pian zi" << std::endl;
            continue;
        }
        if (c == 0)
        {
            int new_set = true;
            for (int k = 0; k < team_set.size(); k++)
            {
                if (team_set[k].count(a) == 1)
                {
                    new_set = false;
                    team_set[k].insert(b);

                    for (int j = 0; j < team_set.size(); j++)
                    {
                        if (j == k)
                        {
                            continue;
                        }

                        if (team_set[j].count(a) || team_set[j].count(b))
                        {
                            for (auto it = team_set[j].begin(); it != team_set[j].end(); ++it)
                            {
                                team_set[k].insert(*it);
                            }
                            team_set.erase(team_set.begin() + j);
                            break;
                        }
                    }
                    break;
                }

                if (team_set[k].count(b) == 1)
                {
                    new_set = false;
                    team_set[k].insert(a);

                    for (int j = 0; j < team_set.size(); j++)
                    {
                        if (j == k)
                        {
                            continue;
                        }

                        if (team_set[j].count(a) || team_set[j].count(b))
                        {
                            for (auto it = team_set[j].begin(); it != team_set[j].end(); ++it)
                            {
                                team_set[k].insert(*it);
                            }
                            team_set.erase(team_set.begin() + j);
                            break;
                        }
                    }
                    break;
                }
            }
            if (new_set)
            {
                std::set<int> temp_set;
                temp_set.insert(a);
                temp_set.insert(b);
                team_set.push_back(temp_set);
            }
        }
        else if (c == 1)
        {
            bool is_team = false;
            for (int k = 0; k < team_set.size(); k++)
            {
                if (team_set[k].count(a) && team_set[k].count(b))
                {
                    is_team = true;
                    std::cout << "we are a team" << std::endl;
                }
            }
            if (!is_team)
            {
                std::cout << "we are not a team" << std::endl;
            }
        }
        else
        {
            std::cout << "da pian zi" << std::endl;
            continue;
        }
    }

    return 0;
}